﻿using System;
using System.Collections.Generic;

#region MIT License text
/*
Copyright (c) 2009 Mark van Straten - Q42 B.V.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#endregion

namespace Q42.Wheels.Api.Nabaztag
{
    /// <summary>
    /// This action is an choreography of light and ears
    /// </summary>
    public class ChoreographyAction : NabaztagAction
    {
        /// <summary>
        /// Title of this choreography
        /// </summary>
        private String title;

        /// <summary>
        /// Title of this choreography
        /// </summary>
        public String Title
        {
            get { return this.title; }
            set { this.title = value; }
        }
        
        /// <summary>
        /// Tempo of this choreography, expressed in Hz
        /// </summary>
        private Int16 tempo;
        /// <summary>
        /// Tempo of this choreography, expressed in Hz
        /// </summary>
        /// <example>10 represents a tempo of a tenth of a second</example>
        public Int16 Tempo {
            get { return this.tempo; }
            set {
                if (value <= 0)
                    throw new ArgumentOutOfRangeException("Tempo must be > 0");
                this.tempo = value; 
            }
        }

        /// <summary>Constructor</summary>
        /// <param name="Title">Title of the choreography for finding it in my.violet.net</param>
        /// <param name="Tempo">The tempo in which the parts are played</param>
        public ChoreographyAction(String Title, Int16 Tempo)
        {
            this.Title = Title;
            this.Tempo = Tempo;

            this.choreographyParts = new List<ChoreographyPart>();
        }

        private List<ChoreographyPart> choreographyParts;
        /// <summary>
        /// The choreography parts to play in this choreography
        /// </summary>
        public List<ChoreographyPart> ChoreographyParts { 
            get { return this.choreographyParts; }
        }

        /// <summary>
        /// Format this action to be sent to the nabaztag API by URL
        /// </summary>
        /// <exception cref="ApplicationException">If no actions are defined</exception>
        /// <returns></returns>
        public override void ToStringList(ref Dictionary<String, String> parameters)
        {
            if (ChoreographyParts.Count == 0)
                throw new ApplicationException("No choreography actions defined");
            if (Title.Equals(String.Empty))
                Title = "Anonymous choreography";
            parameters.Add("chortitle", Title);

            String chor = Tempo + ",";
            foreach (ChoreographyPart action in ChoreographyParts)
                chor += action.GetChoreoGraphy() + ",";
            parameters.Add("chor", chor.Substring(0, chor.Length - 1));//laatste , eraf snoepen
        }
    }
}
